﻿using CTS.Com.Domain.Constants;
using CTS.Com.Domain.Helper;
using CTS.Data.APStorageFiles.Domain.Utils;
using CTS.Data.MACompanyInfos.Domain.Utils;
using CTS.W._150101.Models.Domain.Common.Constants;
using CTS.W._150101.Models.Domain.Model.Client.Contact;

namespace CTS.W._150101.Models.Domain.Logic.Client.Contact
{
    /// <summary>
    /// InitLogic
    /// </summary>
    public class InitLogic
    {
        #region Execute Method
        /// <summary>
        /// Xử lý init.
        /// </summary>
        /// <param name="inputObject">DataModel</param>
        /// <returns>DataModel</returns>
        public InitDataModel Execute(InitDataModel inputObject)
        {
            // Kiểm tra thông tin
            Check(inputObject);
            // Lấy thông tin
            var resultObject = GetInfo(inputObject);
            // Kết quả trả về
            return resultObject;
        }
        #endregion

        #region Private Method
        /// <summary>
        /// Kiểm tra thông tin.
        /// </summary>
        /// <param name="inputObject">DataModel</param>
        private void Check(InitDataModel inputObject)
        {
        }

        /// <summary>
        /// Lấy thông tin.
        /// </summary>
        /// <param name="inputObject">DataModel</param>
        /// <returns>DataModel</returns>
        private InitDataModel GetInfo(InitDataModel inputObject)
        {
            // Khởi tạo biến cục bộ
            var getResult = new InitDataModel();
            var companyCom = new CompanyCom();
            var storageFileCom = new StorageFileCom();
            // Map dữ liệu
            DataHelper.CopyObject(inputObject, getResult);
            // Lấy thông tin
            var code = companyCom.GetString(Logics.LOCALE_DEFAULT, W150101Logics.CD_INFO_CD_CODE, false);
            var name = companyCom.GetString(Logics.LOCALE_DEFAULT, W150101Logics.CD_INFO_CD_NAME, false);
            var email = companyCom.GetString(Logics.LOCALE_DEFAULT, W150101Logics.CD_INFO_CD_EMAIL, false);
            var phone = companyCom.GetString(Logics.LOCALE_DEFAULT, W150101Logics.CD_INFO_CD_PHONE, false);
            var fax = companyCom.GetString(Logics.LOCALE_DEFAULT, W150101Logics.CD_INFO_CD_FAX, false);
            var address = companyCom.GetString(Logics.LOCALE_DEFAULT, W150101Logics.CD_INFO_CD_ADDRESS, false);
            var logoFileCd = companyCom.GetString(Logics.LOCALE_DEFAULT, W150101Logics.CD_INFO_CD_LOGOFILECD, false);
            // Lấy đường dẫn file
            var logoUrl = storageFileCom.GetFileName(Logics.LOCALE_DEFAULT, logoFileCd, false);
            // Gán giá trị trả về
            getResult.Code = code;
            getResult.Name = name;
            getResult.Email = email;
            getResult.Phone = phone;
            getResult.Fax = fax;
            getResult.Address = address;
            getResult.LogoUrl = logoUrl;
            // Kết quả trả về
            return getResult;
        }
        #endregion
    }
}
